/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.pos.domain;

import java.io.Serializable;
import java.text.DecimalFormat;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.swing.text.NumberFormatter;

/**
 *
 * @author suraj
 */
@Entity
@Table(name = "saleItems")
public class SaleLineItem implements LineItem, Serializable {

    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private long id;
    @OneToOne
    private Item item;
    private long quantity;
    @ManyToOne
    private SalesDetail details;

    @Override
    public SalesDetail getDetails() {
        return details;
    }

    @Override
    public long getId() {
        return this.id;
    }

    @Override
    public Item getItem() {
        return this.item;
    }

    @Override
    public long getQuantity() {
        return this.quantity;
    }

    @Override
    public void setDetails(Object details) {
        this.details = (SalesDetail) details;
    }

    @Override
    public void setId(long id) {
        this.id = id;
    }

    @Override
    public void setItem(Item item) {
        this.item = item;
    }

    @Override
    public void setQuantity(long quantity) {
        this.quantity = quantity;
    }

    public double getSaleItemPrice() {
        return this.item.getTotalItemPrice() * this.quantity;
    }

    public String getFormattedSaleItemPrice() {
        DecimalFormat format = new DecimalFormat("###,###.##");
        return format.format(getSaleItemPrice());
    }
}
